package cn.wolfcode.web.sendCallback;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;

@Slf4j
public class DefaultSendCallback implements SendCallback {

    private String tag;
    private Object message;

    public DefaultSendCallback(String tag, Object message) {
        this.tag = tag;
        this.message = message;
    }

    @Override
    public void onSuccess(SendResult sendResult) {
        log.info("[发送消息回调]: {}", JSON.toJSONString(sendResult));
        log.info("[{}] 发送消息成功: msgId={}, status={}", tag, sendResult.getMsgId(), sendResult.getSendStatus());
    }

    @Override
    public void onException(Throwable throwable) {
        log.info("[{}] 发送消息失败, 出现异常, 请及时处理消息: message={}", tag, JSON.toJSONString(message));
        log.error("[" + tag + "] 消息发送失败", throwable);
    }
}
